<template>
  <div class="app-container">
    <ve-line :data="chartDatas"  :settings="chartSettings"
             height="300px"></ve-line>
    <el-form :model="querchartyParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="道路编码" prop="roadId">-->
<!--        <el-input-->
<!--          v-model="queryParams.roadId"-->
<!--          placeholder="请输入道路编码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="道路名称" prop="roadName">-->
<!--        <el-input-->
<!--          v-model="queryParams.roadName"-->
<!--          placeholder="请输入道路名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="隧道编码" prop="tunnelId">-->
<!--        <el-input-->
<!--          v-model="queryParams.tunnelId"-->
<!--          placeholder="请输入隧道编码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="隧道名称" prop="tunnelName">
        <el-input
          v-model="queryParams.tunnelName"
          placeholder="请输入隧道名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="病害处治频率" prop="treatmentFrequency">-->
<!--        <el-input-->
<!--          v-model="queryParams.treatmentFrequency"-->
<!--          placeholder="请输入病害处治频率"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="病害处治方案" prop="treatmentScheme">-->
<!--        <el-input-->
<!--          v-model="queryParams.treatmentScheme"-->
<!--          placeholder="请输入病害处治方案"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="上次病害处治日期" prop="lastTreatmentDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.lastTreatmentDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择上次病害处治日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="病害处治前状况值" prop="lastTreatmentNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.lastTreatmentNumber"-->
<!--          placeholder="请输入病害处治前状况值"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="本次病害处治日期" prop="treatmentDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.treatmentDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择本次病害处治日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="病害处治后状况值" prop="treatmentNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.treatmentNumber"-->
<!--          placeholder="请输入病害处治后状况值"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="处治人员" prop="treatmentPerson">
        <el-input
          v-model="queryParams.treatmentPerson"
          placeholder="请输入病害处治人员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="养护机构" prop="maintenanceOrganization">-->
<!--        <el-input-->
<!--          v-model="queryParams.maintenanceOrganization"-->
<!--          placeholder="请输入养护机构"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="处治状态" prop="treatmentCondition">
<!--        <el-input-->
<!--          v-model="queryParams.treatmentCondition"-->
<!--          placeholder="请输入病害处治状态"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
        <el-select v-model="queryParams.treatmentCondition" placeholder="请输入病害处治状态"  clearable >
          <el-option v-for="(item, index) in fieldtreatmentCondition" :key="index" :label="item.label"
                     :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['biz:treatment:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['biz:treatment:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['biz:treatment:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['biz:treatment:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="treatmentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="记录表编码" align="center" prop="tTreatmentId" />
<!--      <el-table-column label="道路编码" align="center" prop="roadId" />-->
<!--      <el-table-column label="道路名称" align="center" prop="roadName" />-->
<!--      <el-table-column label="隧道编码" align="center" prop="tunnelId" />-->
      <el-table-column label="隧道名称" align="center" prop="tunnelName" />
<!--      <el-table-column label="病害处治内容" align="center" prop="treatmentContent" />-->
<!--      <el-table-column label="病害处治频率" align="center" prop="treatmentFrequency" />-->
<!--      <el-table-column label="病害处治方案" align="center" prop="treatmentScheme" />-->
<!--      <el-table-column label="上次病害处治日期" align="center" prop="lastTreatmentDate" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.lastTreatmentDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="病害处治前状况值" align="center" prop="lastTreatmentNumber" />-->
<!--      <el-table-column label="本次病害处治日期" align="center" prop="treatmentDate" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.treatmentDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="病害处治后状况值" align="center" prop="treatmentNumber" />-->
      <el-table-column label="病害处治人员" align="center" prop="treatmentPerson" />
      <el-table-column label="养护机构" align="center" prop="maintenanceOrganization" />
      <el-table-column label="病害处治状态" align="center" prop="treatmentCondition" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['biz:treatment:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['biz:treatment:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCheck(scope.row)"
            v-hasPermi="['civil:treatment:edit']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改病害处治对话框 -->
    <el-dialog :title="title" :visible.sync="openadd" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!--        公路表：公路名称-->
        <el-form-item label="道路名称"  prop="roadName">
          <el-select v-model="form.roadName" placeholder="请选择道路名称">
            <el-option
              v-for="item in gongluList"
              :key="item.id + ''"
              :label="item.field2"
              :value="item.field2 + ''"
              :disabled="item.status == 1"
            ></el-option>
          </el-select>
        </el-form-item>
        <!--      公路表：根据公路名称确定公路编码-->
        <el-form-item label="道路编码" prop="roadId">
          <el-select v-model="form.roadId" placeholder="请选择道路编码">
            <el-option
              v-for="item in gongluList"
              :key="item.id + ''"
              :label="item.field1"
              :value="item.field1 + ''"
              :disabled="item.status == 1"
              v-if="item.field2 == form.roadName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="隧道编码" prop="tunnelId">
          <el-select v-model="form.tunnelId" placeholder="请选择隧道编码">
            <el-option
              v-for="dict in suidaoList"
              :key="dict.field1 + ''"
              :label="dict.field1"
              :value="dict.field1 + ''"
              v-if="dict.field22 == form.roadName"
            ></el-option>
          </el-select>
        </el-form-item>
        <!--        隧道表：根据隧道编码确定隧道名称-->
        <el-form-item label="隧道名称" prop="tunnelName">
          <el-select v-model="form.tunnelName" placeholder="请选择隧道名称">
            <el-option
              v-for="dict in suidaoList"
              :key="dict.field2 + ''"
              :label="dict.field2"
              :value="dict.field2 + ''"
              v-if="dict.field1 == form.tunnelId"
            ></el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="道路编码" prop="roadId">-->
<!--          <el-input v-model="form.roadId" placeholder="请输入道路编码" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="道路名称"  prop="roadName">-->
<!--          <el-select v-model="form.roadName" placeholder="请选择道路">-->
<!--            <el-option-->
<!--              v-for="item in gongluList"-->
<!--              :key="item.id + ''"-->
<!--              :label="item.field2"-->
<!--              :value="item.field2 + ''"-->
<!--              :disabled="item.status == 1"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="隧道编码" prop="tunnelId">-->
<!--          <el-select v-model="form.tunnelId" placeholder="请选择隧道编码">-->
<!--            <el-option-->
<!--              v-for="dict in suidaoList"-->
<!--              :key="dict.field1 + ''"-->
<!--              :label="dict.field1"-->
<!--              :value="dict.field1 + ''"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="隧道名称" prop="tunnelName">-->
<!--          <el-input v-model="form.tunnelName" placeholder="请输入隧道名称" />-->
<!--        </el-form-item>-->
        <el-form-item label="处治内容">
          <editor v-model="form.treatmentContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="处治频率" prop="treatmentFrequency">
          <el-input v-model="form.treatmentFrequency" placeholder="请输入病害处治频率" />
        </el-form-item>
        <el-form-item label="处治方案" prop="treatmentScheme">
          <el-input v-model="form.treatmentScheme" placeholder="请输入病害处治方案" />
        </el-form-item>
        <el-form-item label="上次日期" prop="lastTreatmentDate">
          <el-date-picker clearable
            v-model="form.lastTreatmentDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上次病害处治日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="前状况值" prop="lastTreatmentNumber">
<!--          <el-input v-model="form.lastTreatmentNumber" placeholder="请输入病害处治前状况值" />-->
          <el-select v-model="form.lastTreatmentNumber" placeholder="请输入病害处治前状况值"  clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in fieldtreatmentNumber" :key="index" :label="item.label"
                       :value="item.value" :disabled="item.disabled"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="本次日期" prop="treatmentDate">
          <el-date-picker clearable
            v-model="form.treatmentDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择本次病害处治日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="后状况值" prop="treatmentNumber">
<!--          <el-input v-model="form.treatmentNumber" placeholder="请输入病害处治后状况值" />-->
          <el-select v-model="form.treatmentNumber" placeholder="请输入病害处治后状况值"  clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in fieldtreatmentNumber" :key="index" :label="item.label"
                       :value="item.value" :disabled="item.disabled"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="处治人员" prop="treatmentPerson">
          <el-input v-model="form.treatmentPerson" placeholder="请输入病害处治人员" />
        </el-form-item>
        <el-form-item label="养护机构" prop="maintenanceOrganization">
          <el-input v-model="form.maintenanceOrganization" placeholder="请输入养护机构" />
        </el-form-item>
        <el-form-item label="处治状态" prop="treatmentCondition">
<!--          <el-input v-model="form.treatmentCondition" placeholder="请输入病害处治状态" />-->
          <el-select v-model="form.treatmentCondition" placeholder="请输入病害处治状态"  clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in fieldtreatmentCondition" :key="index" :label="item.label"
                       :value="item.value" :disabled="item.disabled"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看病害处治对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="道路编码" prop="roadId">
          <el-input v-model="form.roadId"  />
        </el-form-item>
        <el-form-item label="道路名称" prop="roadName">
          <el-input v-model="form.roadName" />
        </el-form-item>
        <el-form-item label="隧道编码" prop="tunnelId">
          <el-input v-model="form.tunnelId" />
        </el-form-item>
        <el-form-item label="隧道名称" prop="tunnelName">
          <el-input v-model="form.tunnelName" />
        </el-form-item>
        <el-form-item label="处治内容">
          <editor v-model="form.treatmentContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="处治频率" prop="treatmentFrequency">
          <el-input v-model="form.treatmentFrequency" />
        </el-form-item>
        <el-form-item label="处治方案" prop="treatmentScheme">
          <el-input v-model="form.treatmentScheme" />
        </el-form-item>
        <el-form-item label="上次日期" prop="lastTreatmentDate">
          <el-date-picker clearable
                          v-model="form.lastTreatmentDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                         >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="前状况值" prop="lastTreatmentNumber">
          <el-input v-model="form.lastTreatmentNumber"  />
        </el-form-item>
        <el-form-item label="本次日期" prop="treatmentDate">
          <el-date-picker clearable
                          v-model="form.treatmentDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="后状况值" prop="treatmentNumber">
          <el-input v-model="form.treatmentNumber"  />
        </el-form-item>
        <el-form-item label="处治人员" prop="treatmentPerson">
          <el-input v-model="form.treatmentPerson" />
        </el-form-item>
        <el-form-item label="养护机构" prop="maintenanceOrganization">
          <el-input v-model="form.maintenanceOrganization" />
        </el-form-item>
        <el-form-item label="处治状态" prop="treatmentCondition">
          <el-input v-model="form.treatmentCondition" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listTreatment, getTreatment, delTreatment, addTreatment, updateTreatment ,exportTreatment} from "@/api/biz/treatment";
import { exportAllmaintenance, getAllmaintenance } from '@/api/biz/allmaintenance'
import { listSuidao } from "@/api/biz/suidao";
import { listGonglu } from "@/api/biz/gonglu";


export default {
  name: "Treatment",
  data() {

    this.chartSettings = {
    }
    return {
      chartData:[],
      chartDatas: {
        columns: ['隧道名称', '处治后状况值','处治前状况值'],
        rows: [
        ]
      },
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 病害处治表格数据
      treatmentList: [],
      //隧道列表
      suidaoList: [],
      //道路列表
      gongluList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示增加或修改的弹出层
      openadd: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roadId: null,
        roadName: null,
        tunnelId: null,
        tunnelName: null,
        treatmentContent: null,
        treatmentFrequency: null,
        treatmentScheme: null,
        lastTreatmentDate: null,
        lastTreatmentNumber: null,
        treatmentDate: null,
        treatmentNumber: null,
        treatmentPerson: null,
        maintenanceOrganization: null,
        treatmentCondition: null
      },
      // 表单参数
      form: {},

      fieldtreatmentCondition: [{
        "label": "未处治",
        "value": "未处治"
      }, {
        "label": "处治中",
        "value": "处治中"
      },{
        "label": "已处治",
        "value": "已处治"
      },
      ],

      fieldtreatmentNumber: [{
        "label": 0,
        "value": 0
      }, {
        "label": 1,
        "value": 1
      },{
        "label": 2,
        "value": 2
      }, {
        "label": 3,
        "value": 3
      },{
        "label": 4,
        "value":4
      },

      ],

      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    listSuidao({}).then((response) => {
      this.suidaoList = response.rows;
    });
    listGonglu({}).then((response) => {
      this.gongluList = response.rows;
    });
  },
  methods: {
    /** 查询病害处治列表 */
    getList() {
      this.loading = true;
      listTreatment(this.queryParams).then(response => {
        this.treatmentList = response.rows;
        this.total = response.total;
        this.chartData=response.rows;
        this.chartDatas.rows=[];
        for(var i =0;i<this.chartData.length;i++){
          this.chartDatas.rows.push({
            '隧道名称':this.chartData[i].tTreatmentId+this.chartData[i].tunnelName,
            '处治后状况值':this.chartData[i].treatmentNumber,
            '处治前状况值':this.chartData[i].lastTreatmentNumber
          })
        }
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.openadd = false;
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        tTreatmentId: null,
        roadId: null,
        roadName: null,
        tunnelId: null,
        tunnelName: null,
        treatmentContent: null,
        treatmentFrequency: null,
        treatmentScheme: null,
        lastTreatmentDate: null,
        lastTreatmentNumber: null,
        treatmentDate: null,
        treatmentNumber: null,
        treatmentPerson: null,
        maintenanceOrganization: null,
        treatmentCondition: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.tTreatmentId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openadd = true;
      this.title = "添加病害处治";
      this.form.roadId = this.$route.query.roadid
      this.form.roadName = this.$route.query.roadname
      this.form.tunnelId = this.$route.query.tunnelid
      this.form.tunnelName = this.$route.query.tunnelname
      this.form.maintenanceOrganization = this.$route.query.maintenanceorganization
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const tTreatmentId = row.tTreatmentId || this.ids
      getTreatment(tTreatmentId).then(response => {
        this.form = response.data;
        this.openadd = true;
        this.title = "修改病害处治";
      });
    },
    /** 查看按钮操作 */
    handleCheck(row) {
      this.reset();
      const tTreatmentId = row.tTreatmentId || this.ids
      getTreatment(tTreatmentId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看病害处治";
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.tTreatmentId != null) {
            updateTreatment(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openadd = false;
              this.getList();
            });
          } else {
            addTreatment(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openadd = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const tTreatmentIds = row.tTreatmentId || this.ids;
      this.$modal.confirm('是否确认删除病害处治编号为"' + tTreatmentIds + '"的数据项？').then(function() {
        return delTreatment(tTreatmentIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  //   /** 导出按钮操作 */
  //   handleExport() {
  //     this.download('biz/treatment/export', {
  //       ...this.queryParams
  //     }, `treatment_${new Date().getTime()}.xlsx`)
  //   }
  // },
  /** 导出按钮操作 */
  handleExport() {
    const queryParams = this.queryParams;
    this.$modal
      .confirm("是否确认导出所有数据项？")
      .then(() => {
        this.exportLoading = true;
        return exportTreatment(queryParams);
      })
      .then((response) => {
        this.download(response.msg);
        this.exportLoading = false;
      })
      .catch(() => {});
  },
},

};
</script>
